/* this class will serialize the gamestate into json format */
package bfgca;
import java.io.File;
import java.io.*;
import com.google.gson.stream.*;

public class Storer {

  private File outFile;
  private JsonWriter store;
  private Map theMap;
  
  public Storer(Map m, File out) throws IOException{
    this.outFile = out;
    this.theMap = m;
    this.store = new JsonWriter(new FileWriter(outFile));
  }

  private void serializeMap() throws IOException{
    store.name("Map").beginObject();                          //begin Map object
    store.name("StarSystems").beginArray();             //begin StarSystem array
    for( StarSystem currSys : theMap.getSystems()){
      store.name(currSys.toString()).beginObject();    //begin StarSystem object
      store.name("Planets").beginArray();                   //begin Planet array
      for(Planet currPlanet : currSys.getSystemPlanets()){
        store.name(currPlanet.getName()).beginObject();    //begin Planet object
        store.name("Type").value(currPlanet.getType());
        store.endObject();                                   //end Planet object        
      }
      store.endArray();                                       //end Planet array
      store.name("Vessels").beginArray();                   //begin Vessel array
      for(Vessel currVessel : currSys.getPresentVessels()){
        store.name(currVessel.getName()).beginObject();    //begin Vessel object
        store.name("Type").value(currVessel.getType());
        store.name("Status").value(currVessel.getStatus());
        store.name("Orders").value(currVessel.getOrders());
        store.endObject();                                   //end Vessel object
      }
      store.endArray();                                       //end Vessel array
      store.endObject();                                 //end StarSystem object
    }
    store.endArray();                                     //end StarSystem array
    store.endObject();                                          //end map object
  }
  
  private void serializePlayers() throws IOException{
  }
}